"use client";
import React, { useState } from "react";
import {
  Button,
  Card,
  Cascader,
  DatePicker,
  Form,
  Input,
  InputNumber,
  Radio,
  Select,
  Switch,
  TreeSelect,
} from "antd";
import { add } from "@/app/utils/http";
import dayjs from "dayjs";
const MyForm = (props) => {
  let [orders, setOder] = useState([]);
  const onFinish: FormProps<FieldType>["onFinish"] = async (values) => {
    console.log("Success:", values);
    try {
      let data=new Date().getTime() 
      const obj = await add({
        id: new Date().getTime(),
        ...values,
        data: dayjs(values.day).format("YYYY-MM-DD"),
      });
      setOder([...orders, obj]);
      setTimeout(() => {
        props.getList();
      }, 0)
    } catch (error) {
      console.log("添加失败：", error);
    }
    props.onCancel();
  };
  return (
    <Form onFinish={onFinish} style={{ maxWidth: 600 }}>
      <Form.Item label="关联订单" name="title">
        <Input />
      </Form.Item>
      <Form.Item label="订单归属人" name="name">
        <Input />
      </Form.Item>
      <Form.Item label="回款期次" name="date">
      <Input />
      </Form.Item>
      <Form.Item label="计划回款金额" name="price">
        <InputNumber />
      </Form.Item>
      <Form.Item label="已回款金额" name="prices">
        <InputNumber />
      </Form.Item>
      <Form.Item label="计划回款日期" name="day">
        <DatePicker />
      </Form.Item>

      <Form.Item label="回款状态" name="state">
        <Radio.Group>
          <Radio value={1}>已完成</Radio>
          <Radio value={2}>已逾期</Radio>
          <Radio value={0}>已回款</Radio>
        </Radio.Group>
      </Form.Item>
      <Form.Item label={null}>
        <Button type="primary" htmlType="submit">
          确定
        </Button>
      </Form.Item>
    </Form>
  );
};

export default MyForm;
